package com.star.controller.admin;

import com.star.dto.UserPageQueryDTO;
import com.star.entity.User;
import com.star.result.PageResult;
import com.star.result.Result;
import com.star.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户管理
 */
@RestController("adminUserController")
@RequestMapping("/admin/user")
@Slf4j
@Api(tags = "管理员端用户管理接口")
public class UserController {
    @Autowired
    private UserService userService;
    /**
     * 用户分页查询
     * @param userPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("用户分页查询")
    public Result<PageResult> page(UserPageQueryDTO userPageQueryDTO){
        log.info("用户分页查询{}", userPageQueryDTO);
        PageResult pageResult = userService.pageQuery(userPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 启用/禁用用户状态
     * @param status 路径参数
     * @param id query参数
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("启用/禁用用户状态")
    public Result<String> updateStatus(@PathVariable Integer status, Long id){
        log.info("启用禁用用户状态{}{}", status, id);
        userService.updateStatus(status, id);
        return Result.success();
    }
    /**
     * 根据id查询用户信息
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询用户信息")
    public Result<User> getById(@PathVariable Long id){
        log.info("商家id{}", id);
        User user = userService.getById(id);
        return Result.success(user);
    }
}
